package com.sneakxy.cloudbase.platform.bean.dto;

import java.util.ArrayList;
import java.util.List;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.springframework.beans.BeanUtils;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.sneakxy.cloudbase.platform.bean.Launcher;
import com.sneakxy.cloudbase.platform.bean.ValidAdd;
import com.sneakxy.cloudbase.platform.bean.ValidEdit;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 自启动信息DTO
 * @author 潜行的虚影
 * @see
 */
@Data
@ApiModel("自启动信息")
@EqualsAndHashCode
@JsonIgnoreProperties(ignoreUnknown = true)
public class LauncherDTO implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8814226429086020357L;

	@NotBlank(groups = {ValidEdit.class})
	@Size(max=32, groups = {ValidEdit.class})
	@ApiModelProperty("启动项ID")
	private String id;

	@NotBlank(groups = {ValidAdd.class, ValidEdit.class})
	@Size(max=10, groups = {ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("启动项名称")
	private String name;

	@NotBlank(groups = {ValidAdd.class, ValidEdit.class})
	@Size(max=50, groups = {ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("启动模块名")
	private String module;

	@Size(max=100, groups = {ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("备注")
	private String memo;

	@NotNull(groups={ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("是否开启")
	private Boolean enable;

	@NotNull(groups={ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("用户是否可以手动控制开启")
	private Boolean manual;

	@NotNull(groups={ValidAdd.class, ValidEdit.class})
	@ApiModelProperty("排序")
	private Integer sort;

	@ApiModelProperty("创建时间")
	private String createtime;

	@ApiModelProperty("更新时间")
	private String updatetime;

	public Boolean isEnable() {
		return enable;
	}
	
	public Boolean isManual() {
		return manual;
	}
	
	public static LauncherDTO from(Launcher entity) {
		LauncherDTO result = new LauncherDTO();
		BeanUtils.copyProperties(entity, result);
		return result;
	}
	
	public static List<LauncherDTO> from(List<Launcher> list) {
		List<LauncherDTO> result = new ArrayList<>(list.size());
		list.forEach(entity -> {
			result.add(from(entity));
		});
		return result;
	}
	
	public static Launcher to(LauncherDTO entity) {
		Launcher result = new Launcher();
		BeanUtils.copyProperties(entity, result);
		return result;
	}
	
	public static List<Launcher> to(List<LauncherDTO> list) {
		List<Launcher> result = new ArrayList<>(list.size());
		list.forEach(entity -> {
			result.add(to(entity));
		});
		return result;
	}

}
